#!/bin/bash
WOEK_NOW=$(dirname $(readlink -f "$0"))"/"
source $WOEK_NOW/config

start() {
	#-c: 表示次数，1 为1次  -w: 表示deadline
	ping -c 1  -w 5 $remote_ip  >/dev/null 
	if [ $? -eq 0 ] ;then
		sleep 10
	fi
	if [ $? -eq 0 ] ;then
		# echo  "ping "$remote_ip" ok" 
		mkdir -p $local_dir
		if mountpoint -q $local_dir ;then
			: #echo "mount exist"  
		else
			mount -t nfs -o nolock $remote_ip":"$remote_dir $local_dir 
		fi
	else
		: # echo  "ping "$remote_ip" Error, exit"
	fi

	if mountpoint -q $local_dir ;then
		echo "success" 
	else   
		echo "Faild"
	fi
}

stop() {
	if mountpoint -q $local_dir ;then
		umount $local_dir
	fi
	:
}

case "$1" in
  start)
 	echo -n "Starting Mount..."
	start  
	;;
  stop)
	echo  "Stopping Mount..."
	stop
	;;
  restart|reload)
	"$0" stop
    sleep 1
	"$0" start
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?

